<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title>我的课程 - 企业培训平台</title>
    <style>
        /* --- Global Layout & Variables (Consistent with other pages) --- */
        :root {
            --sidebar-width: 240px;
            --primary-color: #007bff;
            --info-color: #17a2b8;
            --border-color: #dee2e6;
            --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f4f5f7; margin: 0; color: #333;
        }
        .main-content {
            margin-left: var(--sidebar-width); /* Fixes overlap with sidebar */
            padding: 30px;
        }
        .container-card {
            background-color: #ffffff; border-radius: 8px;
            box-shadow: var(--card-shadow); padding: 25px 30px;
        }
        .page-header {
            margin: 0 0 25px 0; padding-bottom: 20px;
            border-bottom: 1px solid var(--border-color); font-size: 1.8em; color: #333;
        }
        /* --- Alert Messages --- */
        .alert {
            padding: 15px; margin-bottom: 20px; border-radius: 5px; border: 1px solid transparent;
        }
        .alert-success { background-color: #d4edda; color: #155724; border-color: #c3e6cb; }
        .alert-danger { background-color: #f8d7da; color: #721c24; border-color: #f5c6cb; }

        /* --- Course Card Grid --- */
        .course-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 25px;
        }
        .course-card {
            background-color: #fff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
            border: 1px solid #eee;
            transition: transform 0.2s ease-in-out, box-shadow 0.3s ease;
            display: flex;
            flex-direction: column;
        }
        .course-card:hover {
            transform: translateY(-5px);
            box-shadow: var(--card-shadow);
        }
        .course-card-details {
            padding: 20px;
            flex-grow: 1;
            display: flex;
            flex-direction: column;
        }
        .course-card-details h3 {
            font-size: 1.2em;
            color: #212529;
            margin: 0 0 10px 0;
        }
        .course-card-details p {
            font-size: 0.9em;
            color: #6c757d;
            line-height: 1.5;
            margin: 0 0 8px 0;
        }
        .course-card-details .price {
            font-weight: bold;
            color: var(--primary-color);
            font-size: 1.1em;
            margin-top: 15px;
        }
        .card-actions {
            margin-top: 20px;
            padding-top: 15px;
            border-top: 1px solid #f1f1f1;
        }

        .btn {
            display: inline-block; width: 100%; box-sizing: border-box;
            padding: 10px 15px; color: white; text-align: center;
            border-radius: 5px; text-decoration: none; font-size: 0.9em;
            font-weight: 500; transition: all 0.2s ease-in-out;
            cursor: pointer; border: none;
        }
        .btn:hover { filter: brightness(90%); }
        .btn-info { background-color: var(--info-color); }
        .btn-primary { background-color: var(--primary-color); }

        .no-results-message {
            grid-column: 1 / -1; /* Make message span all columns */
            text-align: center; padding: 40px; color: #666;
            background-color: #fafafa; border: 1px dashed #ccc; border-radius: 8px;
        }
        .no-results-message a { margin-top: 15px; }

    </style>
</head>
<body>
<div th:replace="~{fragments/header :: header}"></div>

<div class="main-content">
    <div class="container-card">
        <h1 class="page-header">我的课程</h1>

        <div th:if="${successMessage}" class="alert alert-success" th:text="${successMessage}"></div>
        <div th:if="${errorMessage}" class="alert alert-danger" th:text="${errorMessage}"></div>

        <div class="course-grid">
            <div class="course-card" th:each="course : ${purchasedCourses}">
                <div class="course-card-details">
                    <h3 th:text="${course.couName}">课程名称</h3>
                    <p th:text="${#strings.abbreviate(course.couIntroduction, 80)}">课程简介...</p>
                    <p>讲师：<span th:text="${course.teaId != null ? '讲师ID: ' + course.teaId : '未知'}"></span></p>
                    <p>章节数：<span th:text="${course.couCataNum}"></span></p>
                    <p class="price">购买价格: <span th:text="${course.couPrice != null ? course.couPrice + ' 积分' : '免费'}"></span></p>
                </div>
                <div class="card-actions">
                    <a th:href="@{/course/detail/{id}(id=${course.id})}" class="btn btn-info">进入学习</a>
                </div>
            </div>

            <div th:if="${#lists.isEmpty(purchasedCourses)}" class="no-results-message">
                <p>您目前没有已购买的课程。</p>
                <a th:href="@{/student/courses/browse}" class="btn btn-primary">去浏览课程</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>